Skip to content

fix(#272): expose get_stake_amount and get_all_stakers as query endpoints - #384

Merged
cypriannwokolo2-creator merged 1 commit into
cocor-tech:masterfrom
FaveTeamz:fix/272-dead-code-staking
Aug 31, 2026
Merged

fix(#272): expose get_stake_amount and get_all_stakers as query endpoints#384
cypriannwokolo2-creator merged 1 commit into
cocor-tech:masterfrom
FaveTeamz:fix/272-dead-code-staking

Conversation

@FaveTeamz

Copy link
Copy Markdown
Contributor

Summary

Implements Option A from the issue: exposes get_stake_amount and get_all_stakers as proper public contract entry points in the staking contract, replacing what was previously dead/missing code.

What was implemented

packages/staking/src/types.rs

  • Added StakerList variant to DataKey enum — persistent storage key for the ordered list of active staker addresses.

packages/staking/src/contract.rs

  • init(): initialises StakerList to an empty Vec<Address> on deployment.
  • stake(): appends the user to StakerList after a successful stake. Uses persistent storage so the list survives instance storage TTL expiry.
  • unstake(): removes the user from StakerList when the stake moves to unbonding — addresses in the unbonding period are intentionally excluded from the list.
  • get_stake_amount(env, user) (new): returns only the raw i128 staked token amount for a user (returns 0 if no active stake). Convenience query for clients that don't need the full StakePosition struct.
  • get_all_stakers(env) (new): returns Vec<Address> of all addresses with an active stake. Useful for governance snapshots, leaderboard queries, and off-chain indexing.

packages/staking/src/lib.rs

  • Both new functions are exposed as public #[contractimpl] entry points with doc comments.

Design notes

  • StakerList uses persistent storage (not instance) so it survives ledger TTL expiry for contracts with many stakers.
  • The list is kept in sync atomically within the same stake/unstake transactions — no separate maintenance transaction is needed.
  • get_stake_amount is O(1) — reads a single instance storage entry.
  • get_all_stakers is O(n) in the number of stakers — callers should be aware of this for large lists.

Closes #272

…uery endpoints

The staking contract had no way for clients to query (a) the plain token
amount staked by a user without receiving the full StakePosition struct,
or (b) the list of all currently active stakers.

Changes:
- types.rs: add StakerList variant to DataKey enum — persistent storage
  key for the ordered list of active staker addresses.
- contract.rs:
  * init(): initialise StakerList to an empty Vec<Address>.
  * stake(): append user to StakerList after a successful stake.
  * unstake(): remove user from StakerList when stake is moved to
    unbonding — unbonding addresses are not in the list.
  * get_stake_amount(): new query that returns just the i128 staked
    amount (0 if no active stake). Convenience alternative to
    get_stake() for callers that don't need the full StakePosition.
  * get_all_stakers(): new query that returns Vec<Address> of all
    addresses with an active stake. Useful for governance snapshots
    and leaderboard queries.
- lib.rs: expose both new functions as public contract entry points.

Closes cocor-tech#272
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@FaveTeamz Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@cypriannwokolo2-creator
cypriannwokolo2-creator merged commit d4a0352 into cocor-tech:master Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dead code: query_stake_amount and query_all_stakers not exposed

2 participants